package com.beidouin.GnssMain.utils;

import android.util.Base64;

import java.io.UnsupportedEncodingException;

/**
 * Created by Ziji on 2017/8/3.
 */

public class Base64utils {
        // 加密
        public static String getBase64(String str) {
            String result = "";
            if( str != null) {
                try {
                    result = new String(Base64.encode(str.getBytes("utf-8"), Base64.NO_WRAP),"utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
            return result;
        }

    public static String getBase64(byte[] bytes) {
        String result = "";
        if( bytes != null) {
            result = new String(Base64.encode(bytes, Base64.NO_WRAP));
        }
        return result;
    }



        // 解密
        /*public static String getFromBase64(String str) {
            String result = "";
            if (str != null) {
                try {
                    result = new String(Base64.decode(str, Base64.NO_WRAP), "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
            return result;
        }*/
    public static byte[] getFromBase64(String str) {
        //byte[] result=new byte[0];
        if (str != null) {
            byte[] result = Base64.decode(str, Base64.NO_WRAP);
            return result;
        }
        else return null;
    }
}
